package com.xu.ai.model.ollama.controller;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.ollama.api.OllamaChatOptions;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

import com.xu.ai.model.ollama.advisor.ReasoningContentAdvisor;

/**
 * ollama chat controller
 *
 * @author xuguan
 * @since 2025/11/9
 */
@RestController
@RequestMapping("/api/ollama/chat")
public class OllamaChatController {

	private final ChatClient chatClient;

	public OllamaChatController(ChatClient.Builder chatClientBuilder) {
		this.chatClient = chatClientBuilder
				.defaultOptions(OllamaChatOptions.builder()
						.enableThinking()
						.build())
				.defaultAdvisors(SimpleLoggerAdvisor.builder().build())
				.defaultAdvisors(new ReasoningContentAdvisor())
				.build();
	}

	@RequestMapping("/thinking")
	public Flux<String> thinking() {
		return this.chatClient.prompt()
				.user("""
						你是一个经验丰富的投资理财专家, 精通于金融理财.
						对于一个全部身家30万的中年男性, 请深度思考后给他一个最佳理财建议.
						""")
				.stream()
				.content();
	}
}
